package com.jyxd.web.controller.basic;

import com.jyxd.web.data.basic.NurseRecordForm;
import com.jyxd.web.data.dto.HttpResult;
import com.jyxd.web.error.JyxdException;
import com.jyxd.web.mq.HisViewProduction;
import com.jyxd.web.service.assessment.basic.NurseRecordFormService;
import com.jyxd.web.service.patient.PatientService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.text.ParseException;
import java.util.Map;

@Api(tags = "护理单三合一相关接口")
@RestController
@RequestMapping(value = "/NurseRecordForm")
public class NurseRecordFormController {
    private static Logger logger = LoggerFactory.getLogger(NurseRecordFormController.class);

    @Autowired
    private NurseRecordFormService nurseRecordFormService;
    @Autowired
    private PatientService patientService;

    private HisViewProduction hisViewProduction;

    /**
     * 增加一条三合一护理单表记录
     *
     * @return
     */
    @ApiOperation("增加或修改一条三合一护理单表记录")
    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    public HttpResult insert(@RequestBody NurseRecordForm nurseRecordForm, HttpSession session) {
        return nurseRecordFormService.saveOrUpdateData(nurseRecordForm, session);
    }

    /**
     * 删除生命体征表记录
     *
     * @param
     * @return
     */
    @ApiOperation("删除")
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public HttpResult delete(@RequestBody NurseRecordForm nurseRecordForm, HttpSession session) {
        return nurseRecordFormService.delete(nurseRecordForm,session);
    }

    /**
     * 根据条件分页查询生命体征表记录列表（也可以不分页）
     *
     * @param map
     * @return
     */
    @ApiOperation("查询")
    @RequestMapping(value = "/queryList", method = RequestMethod.POST)
    public HttpResult queryList(@RequestBody(required = false) Map<String, Object> map) throws ParseException {
        return nurseRecordFormService.queryListV2(map);
    }

    /**
     * 获取有创血压的列表页面
     */
    @ApiOperation("获取有创血压的列表页面")
    @RequestMapping(value = "/queryABPList", method = RequestMethod.POST)
    public HttpResult queryABPList(@RequestBody(required = false) Map<String, Object> map) {
        return nurseRecordFormService.queryABPList(map);
    }


    /**
     * 三表合一余量沿用
     *
     * @return
     */
    @ApiOperation("三表合一余量沿用")
    @RequestMapping(value = "/getResidualUseById", method = RequestMethod.POST)
    public HttpResult getResidualUseById(@RequestBody NurseRecordForm nurseRecordForm, HttpSession session) throws ParseException {
        try{
            return nurseRecordFormService.getResidualUseById(nurseRecordForm, session);
        } catch (JyxdException e){
            return new HttpResult(500,e.getMessage());
        }
    }

    /**
     * 总结小结接口
     */
    @ApiOperation("总结小结接口")
    @RequestMapping(value = "/inOutSummary", method = RequestMethod.POST)
    public HttpResult inOutSummary(@RequestBody Map<String, Object> map, HttpSession session) {
        return nurseRecordFormService.inOutSummary(map, session);
    }

    /**
     * 查询是否可以进行修改出入量数据
     *
     * @param map
     * @return
     */
    @ApiOperation("查询出入量数据是否存在沿用数据")
    @RequestMapping(value = "/byParentIdCount", method = RequestMethod.POST)
    public HttpResult isUpdateData(@RequestBody Map<String, Object> map) {
        return nurseRecordFormService.isUpdateData(map);
    }

    /**
     * 查询最新数据是否被接班
     *
     * @param map
     * @return
     */
    @ApiOperation("查询最新数据是否被接班")
    @RequestMapping(value = "/isCarryData", method = RequestMethod.POST)

    public HttpResult isCarryData(@RequestBody Map<String, Object> map, HttpSession session) {
        return nurseRecordFormService.isCarryData(map,session);
    }
    /**
     * 查询最新数据并赋值新的生命体征
     *
     * @param map
     * @return
     */
    @ApiOperation("查询最新数据并赋值新的生命体征")
    @RequestMapping(value = "/getNewData", method = RequestMethod.POST)

    public HttpResult getNewData(@RequestBody Map<String, Object> map) {
        return nurseRecordFormService.getNewData(map);
    }

    @ApiOperation("批量修改时间范围内护理单字段内容")
    @RequestMapping(value = "/batchUpdateField", method = RequestMethod.POST)
    @ResponseBody
    public HttpResult batchUpdateField(@RequestBody Map<String, Object> map, HttpSession session) {
        return nurseRecordFormService.batchUpdateField(map,session);
    }

    @ApiOperation("批量修改时间范围内护理单字段内容校验")
    @RequestMapping(value = "/batchUpdateFieldCheck", method = RequestMethod.POST)
    @ResponseBody
    public HttpResult batchUpdateFieldCheck(@RequestBody Map<String, Object> map) {
        return nurseRecordFormService.batchUpdateFieldCheck(map);
    }
}
